package com.kawaiior.asoulworld.events;

import com.kawaiior.asoulworld.IdlFramework;
import com.kawaiior.asoulworld.capability.AsoulAirPower;
import com.kawaiior.asoulworld.capability.AsoulTimePower;
import com.kawaiior.asoulworld.capability.AvaPower;
import com.kawaiior.asoulworld.capability.CapabilityRegistryHandler;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;

@Mod.EventBusSubscriber(modid = IdlFramework.MODID)
public class AsoulTickEvent {

    @SubscribeEvent
    public static void AsoulPlayerTickEvent(TickEvent.PlayerTickEvent event){
        World world = event.player.world;
        if (world.isRemote || event.player.ticksExisted % 20 != 0 || event.phase != TickEvent.Phase.END) return;

        AvaPower avaPower = event.player.getCapability(CapabilityRegistryHandler.AVA_POWER, null);
        if (avaPower != null && avaPower.isHot()){
            avaPower.coolDown();
        }

        AsoulAirPower asoulAirPower = event.player.getCapability(CapabilityRegistryHandler.ASOUL_AIR_POWER, null);
        if (asoulAirPower != null && asoulAirPower.hasHealth()){
            asoulAirPower.cutHealth(world);
        }

        AsoulTimePower asoulTimePower = event.player.getCapability(CapabilityRegistryHandler.ASOUL_TIME_POWER, null);
        if (asoulTimePower != null){
            asoulTimePower.setTime(new int[]{(int)event.player.posX, (int)event.player.posY, (int)event.player.posZ});
            asoulTimePower.setPlayerHealth((int)event.player.getHealth());
            if (asoulTimePower.isHot()) {
                asoulTimePower.coolAsoulTime();
            }
        }
    }

}
